package com.hmall.item.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.vo.InsertVo;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.stereotype.Service;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    /**
     * 修改指定商品的上下架状态
     * @param id
     * @param status
     */
    @Override
    public void updateStatus(Long id, Integer status) {
        //使用build模式创建Item对象
        Item build = Item.builder()
                         .status(status)
                         .id(id)
                         .build();
        this.updateById(build);
    }

    @Override
    public void updateItem(InsertVo insertVo) {
        Item build = Item.builder().name(insertVo.getName()).price(insertVo.getPrice()).stock(insertVo.getStock())
                .image(insertVo.getImage()).category(insertVo.getCategory())
                .brand(insertVo.getBrand()).spec(insertVo.getSpec())
                .isAD(insertVo.getIsAD()).build();
        this.update(build, new QueryWrapper<Item>().eq("id", insertVo.getId()));
    }

    @Override
    public void deleteByID(Long id) {
        this.removeById(id);
    }
}
